package me.zhengjie.sqlservice.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import me.zhengjie.mapper.WcsLineBodyAbnormalMapper;
import me.zhengjie.pojo.entity.WcsLineBodyAbnormal;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class WcsLineBodyAbnormalService extends ServiceImpl<WcsLineBodyAbnormalMapper, WcsLineBodyAbnormal> implements me.zhengjie.sqlservice.WcsLineBodyAbnormalService {

    private final WcsLineBodyAbnormalMapper wcsLineBodyAbnormalMapper;

    @Override
    public boolean inertAbnormal(WcsLineBodyAbnormal wcsLineBodyAbnormal) {
        return wcsLineBodyAbnormalMapper.insert(wcsLineBodyAbnormal) >0;
    }

    @Override
    public List<WcsLineBodyAbnormal> selectAll() {
        return wcsLineBodyAbnormalMapper.selectList(null);
    }

    @Override
    public boolean delectId(Integer id) {
        return wcsLineBodyAbnormalMapper.deleteById(id) >0;
    }

    @Override
    public List<WcsLineBodyAbnormal> selectContainer(String container) {
        LambdaQueryWrapper<WcsLineBodyAbnormal> wcsLineBodyAbnormalLambdaQueryWrapper = new LambdaQueryWrapper<>();
        wcsLineBodyAbnormalLambdaQueryWrapper.eq(WcsLineBodyAbnormal::getContainerCode,container)
                .orderByDesc(WcsLineBodyAbnormal::getCreateTime);
        return wcsLineBodyAbnormalMapper.selectList(wcsLineBodyAbnormalLambdaQueryWrapper);
    }

    @Override
    public boolean updateAbnormalInformation(String containerCode, String ng) {
        LambdaUpdateWrapper<WcsLineBodyAbnormal> wcsLineBodyAbnormalLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        wcsLineBodyAbnormalLambdaUpdateWrapper.set(WcsLineBodyAbnormal::getAbnormalInformation,ng)
                .set(WcsLineBodyAbnormal::getCreateTime, LocalDateTime.now())
                .eq(WcsLineBodyAbnormal::getContainerCode,containerCode);
        return wcsLineBodyAbnormalMapper.update(null, wcsLineBodyAbnormalLambdaUpdateWrapper) > 0;
    }
}
